import Vue from 'vue'
import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

const router = new Router({
  linkActiveClass: 'active',
  routes: [
    {
      path: '/',
      redirect: "/home"
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import(/* webpackChunkName: "home" */ '@/views/home/index.vue'),
      meta: {
        title: '首页'
      }
    },

    {
      path: '/about',
      name: 'About',
      component: () => import('@/views/about/index.vue'),
      meta: {
        title: '关于我们'
      }
    },
    {
      path: '/programme',
      name: 'Programme',
      component: () => import('@/views/programme/index.vue'),
      meta: {
        title: '解决方案'
      }
    },
    {
      path: '/advantag',
      name: 'Advantag',
      component: () => import('@/views/advantag/index.vue'),
      meta: {
        title: '惠保优势'
      }
    },
    {
      path: '/join',
      name: 'Join',
      component: () => import('@/views/join/index.vue'),
      meta: {
        title: '加入我们'
      }
    },
    {
      path: '/news',
      name: 'News',
      component: () => import('@/views/news/index.vue'),
      
      children: [
        {
          path: 'list',
          name: 'Newslist',
          component: () => import('@/views/news/list.vue'),
          meta: {
            title: '新闻列表'
          },
        }, {
          path: 'detail',
          name: 'NewsDetail',
          component: () => import('@/views/news/detail.vue'),
          meta: {
            title: '新闻详情'
          },
        },

      ]
    },
    {
      path: '*',
      name: '404',
      component: () => import('@/views/404.vue')
    },

  ]
})

router.beforeEach((to, from, next) => {
  document.title = `${window.CONST.PROJECT_TITLE}${to.meta.title?('-'+to.meta.title):''} `
  next()
})

export default router